package tomcat.connector;

import tomcat.Utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AqieServlet{
    public void service(ServletRequest request, ServletResponse response) throws IOException {
        PrintWriter out = response.getWriter();
        out.println(ConnectorUtil.renderStatus(HttpStatus.SC_OK));
        out.println("what time is it now");
        out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(new Date()));

        // servlet 开发者 使用 服务器开发者代码
        // 外观模式
        DynamicRequest request1 = (DynamicRequest)request;
    }

    public static void main(String[] args) throws MalformedURLException, IllegalAccessException, InstantiationException, ClassNotFoundException {
        String servletRequest = "GET /servlet/AqieServlet HTTP/1.1";
        DynamicRequest request = (DynamicRequest) Utils.getRequest(servletRequest);
        ServletProcessor processor = new ServletProcessor();
        URLClassLoader loader = processor.getServletClassLoader();
        Servlet servlet = processor.getServlet(loader, request);
        System.out.println(servlet.getClass().getSimpleName());

    }
}
